package com.jcfk.system.controller;

import cn.hutool.core.util.StrUtil;
import com.jcfk.common.business.enums.AvailableStatus;
import com.jcfk.common.business.log.annotation.RequestLogHeader;
import com.jcfk.common.business.utils.DataBindHelper;
import com.jcfk.common.web.domain.DataPage;
import com.jcfk.common.web.domain.ReqPageParam;
import com.jcfk.common.web.domain.RetPage;
import com.jcfk.common.web.domain.RetResult;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;

import com.jcfk.system.domain.query.OaKeyworkWeeklyActualQuery;
import com.jcfk.system.domain.dto.OaKeyworkWeeklyActualDTO;
import com.jcfk.system.service.OaKeyworkWeeklyActualService;
import com.jcfk.common.core.utils.ExcelUtils;
/**
 * 周报实际完成
 *
 * @author awei
 * @email 522891237@gqq.com
 * @date 2024-04-02
 */
@Api(tags = {"周报实际完成管理"})
@RestController
@RequestMapping("oakeyworkweeklyactual")
public class OaKeyworkWeeklyActualController {
    @Autowired
    private OaKeyworkWeeklyActualService oaKeyworkWeeklyActualService;

    /**
     * 分页列表
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "ReqPageParam<OaKeyworkWeeklyActualQuery>", name = "requestParam", value = "", required = true)
    })
    @ApiOperation("分页查询周报实际完成")
    @PostMapping("/queryByPage")
    public RetPage<OaKeyworkWeeklyActualDTO> queryByPage(@RequestBody ReqPageParam<OaKeyworkWeeklyActualQuery> requestParam) {
        DataPage<OaKeyworkWeeklyActualDTO> page = new DataPage<OaKeyworkWeeklyActualDTO>((long) requestParam.getCurrent(),
                (long) requestParam.getSize(),
                requestParam.getSort().getOrderItem(),
            OaKeyworkWeeklyActualDTO.class);
        page = oaKeyworkWeeklyActualService.queryByPage(page, requestParam.getData());

        return new RetPage<>(page);
    }


    /**
     *  周报实际完成
     * 根据id 查询详情
     */
    @ApiOperation("查询周报实际完成")
    @GetMapping("/get/{id}")
    public RetResult<OaKeyworkWeeklyActualDTO> get(@PathVariable("id") String id) {
            OaKeyworkWeeklyActualDTO item = oaKeyworkWeeklyActualService.get(id);
        return RetResult.ok(item);
    }

    /**
     * 添加/更新管理周报实际完成
     */
    @ApiOperation("保存周报实际完成")
    @PostMapping("/save")
    @RequestLogHeader(modular = "周报实际完成管理", businessType = "保存")
    public RetResult<?> save(@RequestBody @Valid OaKeyworkWeeklyActualDTO oaKeyworkWeeklyActual) {
        // 数据校验
        RetResult ret = oaKeyworkWeeklyActualService.isValid(oaKeyworkWeeklyActual);
        if (!ret.getCode().equals(RetResult.SUCCESS)) {
            return ret;
        }

        if (StrUtil.isEmpty(oaKeyworkWeeklyActual.getId())){
            // 新增
            oaKeyworkWeeklyActualService.insert(oaKeyworkWeeklyActual);
        } else{
            // 更新
            oaKeyworkWeeklyActualService.update(oaKeyworkWeeklyActual);
        }
        return RetResult.ok();

    }

    /**
     *  批量删除周报实际完成
     */
    @ApiOperation("批量删除周报实际完成")
    @PostMapping("/delete")
    @RequestLogHeader(modular = "周报实际完成管理", businessType = "批量删除")
    public RetResult<?> delete(@RequestBody OaKeyworkWeeklyActualDTO oaKeyworkWeeklyActual) {
        return RetResult.ok(oaKeyworkWeeklyActualService.removeBigBatch(oaKeyworkWeeklyActual.getIds()));
    }



}
